﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Kinect;

namespace Fizbin.Kinect.Gestures.Segments
{
    class JoinedHandsSegment1 : IRelativeGestureSegment
    {
        private System.Windows.Forms.TextBox tex;

        public JoinedHandsSegment1(System.Windows.Forms.TextBox tex)
        {
            // TODO: Complete member initialization
            this.tex = tex;
        }
        /// <summary>
        /// Checks the gesture.
        /// </summary>
        /// <param name="skeleton">The skeleton.</param>
        /// <returns>GesturePartResult based on if the gesture part has been completed</returns>
        public GesturePartResult CheckGesture(Skeleton skeleton)
        {
            float range = 0.1f;
            Joint leftHand = skeleton.Joints[JointType.HandLeft];
            Joint rightHand = skeleton.Joints[JointType.HandRight];
            // Right and Left Hand in front of Shoulders

            float xMen = (leftHand.Position.X - range), xMai = (leftHand.Position.X + range),
                  yMen = (leftHand.Position.Y - range), yMai = (leftHand.Position.Y + range),
                  zMen = (leftHand.Position.Z - range), zMai = (leftHand.Position.Z + range);


            float handDX = rightHand.Position.X,
                  handDY = rightHand.Position.Y,
                  handDZ = rightHand.Position.Z;

            this.tex.Text = "Mao esquerda[x]: " + skeleton.Joints[JointType.HandLeft].Position.X +
                            "  Mao esquerda[y]: " + skeleton.Joints[JointType.HandLeft].Position.Y +
                            "  Mao esquerda[z]: " + skeleton.Joints[JointType.HandLeft].Position.Z + "\r\n" +
                            "Mao direita[x]: " + skeleton.Joints[JointType.HandRight].Position.X +
                            "  Mao direita[y]: " + skeleton.Joints[JointType.HandRight].Position.Y +
                            "  Mao direita[z]: " + skeleton.Joints[JointType.HandRight].Position.Z + "\r\n";

            if ((xMen < handDX && handDX < xMai) &&
               (yMen < handDY && handDY < yMai) &&
               (zMen < handDZ && handDZ < zMai))
            {
                return GesturePartResult.Suceed;
            }
            return GesturePartResult.Pausing;
            //if (skeleton.Joints[JointType.HandLeft].Position.Z < skeleton.Joints[JointType.ElbowLeft].Position.Z && skeleton.Joints[JointType.HandRight].Position.Z < skeleton.Joints[JointType.ElbowRight].Position.Z)

            //            // Hands very close
            //            if (skeleton.Joints[JointType.HandRight].Position.X - skeleton.Joints[JointType.HandLeft].Position.X < 0)
            //            {
            //                return GesturePartResult.Suceed;
            //            }

            //            return GesturePartResult.Pausing;
            //        }
        }
    }
}
